<?php
/**
 * zeus_printer
 *
 * @package
 * @author xexplorer
 * @copyright Copyright (c) 2008
 * @version $Id$
 * @access public
 */
class zeus_printer {
    private $buffer;
    private $column;
    private $row;
    private $sign;
    /**
     * zeus_printer::__construct()
     */
    function __construct()
    {
    }
    /**
     * zeus_printer::__destruct()
     */
    function __destruct()
    {
    }
    /**
     * zeus_printer::printWordHead()
     *
     * @return
     */
    public function printWordHead($sTitle = "")
    {
        $this->buffer[] = "<html xmlns:v='urn:schemas-microsoft-com:vml'";
        $this->buffer[] = "xmlns:o='urn:schemas-microsoft-com:office:office'";
        $this->buffer[] = "xmlns:w='urn:schemas-microsoft-com:office:word'";
        $this->buffer[] = "xmlns='http://www.w3.org/TR/REC-html40'>";
        $this->buffer[] = "<head>";
        $this->buffer[] = "<meta http-equiv=Content-Type content='text/html; charset=utf-8'>";
        $this->buffer[] = "<meta name=ProgId content=Word.Document>";
        $this->buffer[] = "<meta name=Generator content='Microsoft Word 11'>";
        $this->buffer[] = "<meta name=Originator content='Microsoft Word 11'>";
        $this->buffer[] = zeus_style('printer', 'screen');
		$this->buffer[] = zeus_style('printer', 'print');
        $this->buffer[] = "</head>";
        $this->buffer[] = "<title>";
        $this->buffer[] = $sTitle;
        $this->buffer[] = "</title>";
    }
    /**
     * zeus_printer::write()
     *
     * @param string $sContent
     * @return
     */
    public function write($sContent = "")
    {
        $this->buffer[] = $sContent;
    }
    /**
     * zeus_printer::output()
     *
     * @return
     */
    public function output()
    {
        $this->buffer[] = "</html>";
        echo implode("", $this->buffer);
    }
    public function setRowPerPage($iRow = 25)
    {
        $this->row = $iRow;
    }
    /**
     * zeus_printer::pageBreak()
     *
     * @return
     */
    public function pageBreak()
    {
        $this->buffer[] = "<div style='page-break-before: always;'>";
        $this->buffer[] = "<!--[if IE 7]>";
        $this->buffer[] = "<br style='height:0; line-height:0'>";
        $this->buffer[] = "<![endif]-->";
        $this->buffer[] = "</div>";
    }
    public function setTHead($aHead = array())
    {
        $this->thead = $aHead;
    }
    public function printTHead()
    {
        $this->column = 0;
        $this->buffer[] = "<thead><tr>";
        if (isset($this->thead) && null != $this->thead) {
            foreach($this->thead AS $head) {
                $this->buffer[] = "<td>";
                $this->buffer[] = $head;
                $this->buffer[] = "</td>";
                $this->column++;
            }
        } else {
            return false;
        }
        $this->buffer[] = "<tr></thead>";
    }
    public function setCaption($sCaption = "")
    {
        $this->caption = $sCaption;
    }
    public function setTBStyle($sStyle = "apply-table")
    {
        $this->tbStyle = $sStyle ;
    }
    public function tbStart()
    {
        $this->buffer[] = "<table cellspacing='0' id='" . $this->tbStyle . "'>";
        $this->buffer[] = "<caption>";
        $this->buffer[] = $this->caption;
        $this->buffer[] = "</caption>";
    }
    public function tbEnd()
    {
        $this->buffer[] = "</table>";
    }
    public function printTBody($aBody = array())
    {
        if (isset($aBody) && null != $aBody) {
            foreach($aBody AS $row_key => $row_value) {
                $this->buffer[] = "<tr>";
                $this->printColumn($row_value);
                $this->buffer[] = "</tr>";
                if (count($aBody) - 1 > $row_key) {
                    if (0 == ($row_key + 1) % $this->row && (($row_key + 1) >= $this->row)) {
                        $this->tbEnd();
                        $this->pageBreak();
                        $this->tbStart();
                        $this->printTHead();
                    } else {
                        zeus_do_nothing();
                    }
                } elseif (count($aBody) - 1 == $row_key) {
                    $this->tbEnd();
                    $this->printSign();
                } else {
                    zeus_do_nothing();
                }
            }
        } else {
            return false;
        }
    }
    public function printColumn($aRow = array())
    {
        if (isset($aRow) && null != $aRow) {
            foreach($aRow AS $data) {
                $this->buffer[] = "<td>";
                $this->buffer[] = $data;
                $this->buffer[] = "</td>";
            }
        } else {
            return false;
        }
    }
    public function setSign($sSign = "")
    {
        $this->sign = $sSign;
    }

    public function printSign()
    {
        $this->buffer[] = "<br>";
        $this->buffer[] = "<div class='left'>";
        $this->buffer[] = _e('Print date:') . date('Y') . "-" . date('m') . "-" . date('d');
        $this->buffer[] = "</div>";
        $this->buffer[] = "<div class='right'>";
        $this->buffer[] = $this->sign . " ___________ (" . _e("Sign") . ")";
        $thin->buffer[] = $this->pageBreak();
        $this->buffer[] = "</div>";
    }
}

?>